package per.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import per.com.bean.Order;
import per.com.bean.Trip;
import per.com.common.ServerResponse;
import per.com.service.PcOrderService;
import per.com.service.PcTripService;
import per.com.service.PcUserOrderService;
import per.com.service.PcUsersService;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Author: plx
 * @Date: 2019/5/28 10:13
 * @Version 1.0
 */
@Controller
@RequestMapping("/index")
public class indexController {
    @Autowired
    @Qualifier("PcOrderServiceId")
    private PcOrderService pcOrderService;

    @Autowired
    @Qualifier("PcUserOrderServiceId")
    private PcUserOrderService pcUserOrderService;

    @Autowired
    @Qualifier("PcTripServiceId")
    private PcTripService pcTripService;

    @Autowired
    @Qualifier("PcUsersServiceId")
    private PcUsersService pcUsersService;

    /**
     * 用户登录后提醒当天的行程
     * @return
     */
    @RequestMapping(value = "/remindUser",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse remindTrip(@RequestParam String userId){
        if(userId != null){
            List<Order> list = pcOrderService.getOrderByUserId(userId);
            for(Order order :list){
                if(order != null){
                    Date tripTime = order.getTime();
                    String date =  new SimpleDateFormat("yyyy-MM-dd").format(tripTime);
                    String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
                    if(now.equals(date)) {
                        return ServerResponse.createBySuccess("您今日有订单需要完成",order);
                    }
                }
            }
        }
        return null;
    }
}
